package io.renren.minimito.service.impl;

import com.alibaba.druid.util.StringUtils;
import io.renren.minimito.entity.ImUserEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.minimito.dao.ImGroupmsgDao;
import io.renren.minimito.entity.ImGroupmsgEntity;
import io.renren.minimito.service.ImGroupmsgService;


@Service("imGroupmsgService")
public class ImGroupmsgServiceImpl extends ServiceImpl<ImGroupmsgDao, ImGroupmsgEntity> implements ImGroupmsgService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<ImGroupmsgEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (!StringUtils.isEmpty(key)){
            wrapper.eq("id",key)
                    .or().eq("group_id",key)
                    .or().eq("user_id",key)
                    .or().like("message",key)
            ;
        }


        IPage<ImGroupmsgEntity> page = this.page(
                new Query<ImGroupmsgEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}